import type {
  NavigationGuardNext,
  RouteLocationNormalized,
  RouteLocationNormalizedLoaded,
  RouteRecordRaw,
} from 'vue-router'
import { LayoutTypography, LayoutBasic, LayoutConsole } from '@/layout'

export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'root',
    redirect: { name: 'overview' },
    meta: {
      title: '首页',
    },
  },
  {
    path: '/large',
    name: 'large',
    redirect: { name: 'overview' },
    component: LayoutTypography,
    meta: {
      title: '大屏统计',
    },
    children: [
      {
        path: 'overview',
        name: 'overview',
        component: () => import('@/views/large/overview.tsx'),
        meta: {
          title: '统计概览',
        },
      },
    ],
  },
  {
    path: '/console',
    name: 'console',
    redirect: { name: 'monitoring' },
    component: LayoutConsole,
    meta: {
      title: '系统控制台',
    },
    children: [
      {
        path: 'monitoring',
        name: 'monitoring',
        component: () => import('@/views/console/monitoring.tsx'),
        meta: {
          title: '监控视频',
        },
      },
    ],
  },
  {
    path: '/preferences',
    name: 'preferences',
    component: LayoutTypography,
    redirect: { name: 'static' },
    meta: {
      title: '系统偏好',
    },
    children: [
      {
        path: 'static',
        name: 'static',
        component: () => import('@/views/preferences/static.tsx'),
        meta: {
          title: '静态页面',
        },
      },
      {
        path: 'settings',
        name: 'settings',
        component: () => import('@/views/preferences/settings.tsx'),
        meta: {
          title: '偏好设置',
        },
      },
    ],
  },
  {
    path: '/system',
    name: 'system',
    redirect: { name: 'dashboard'},
    component: LayoutConsole,
    meta: {
      title: '系统管理',
    },
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/system/dashboard.tsx'),
        meta: {
          title: '系统概览',
        },
      },
      {
        path: 'monitor',
        name: 'monitor',
        component: () => import('@/views/system/monitor.tsx'),
        meta: {
          title: '系统监控',
        },
      },
    ],
  },
  {
    path: '/auth',
    name: 'auth',
    component: LayoutBasic,
    redirect: { name: 'login' },
    meta: {
      title: '用户认证',
    },
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import('@/views/auth/login.tsx'),
        meta: {
          title: '登录',
        },
      },
      {
        path: 'register',
        name: 'register',
        component: () => import('@/views/auth/register.tsx'),
        meta: {
          title: '注册',
        },
      },
      {
        path: 'forgot',
        name: 'forgot',
        component: () => import('@/views/auth/forgot.tsx'),
        meta: {
          title: '忘记密码',
        },
      },
    ],
  },
  {
    path: '/helper',
    name: 'helper',
    component: LayoutConsole,
    redirect: { name: 'book' },
    meta: {
      title: '帮助文档',
    },
    children: [
      {
        path: 'book',
        name: 'book',
        component: () => import('@/views/helper/book.tsx'),
        meta: {
          title: '说明手册',
        },
      },
      {
        path: 'center',
        name: 'center',
        component: () => import('@/views/helper/center.tsx'),
        meta: {
          title: '帮助中心',
        }
      }
    ]
  }
]

export const authPermission = (
  from: RouteLocationNormalizedLoaded,
  to: RouteLocationNormalized,
  next: NavigationGuardNext,
) => {
  document.title = `${from.meta.title || ""} 💧 水务管理系统`
  next()
}
